package com.ruoyi.trans.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.trans.domain.BaSupplier;
import com.ruoyi.trans.mapper.BaSupplierMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.trans.service.IBaSupplierService;
import com.ruoyi.common.core.text.Convert;

import javax.swing.table.TableRowSorter;

/**
 * 供应商Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-05
 */
@Service
public class BaSupplierServiceImpl implements IBaSupplierService 
{
    @Autowired
    private BaSupplierMapper baSupplierMapper;

    /**
     * 查询供应商
     * 
     * @param sId 供应商主键
     * @return 供应商
     */
    @Override
    public BaSupplier selectBaSupplierBySId(Long sId)
    {
        return baSupplierMapper.selectBaSupplierBySId(sId);
    }

    @Override
    public List<BaSupplier> selectEnableSupplier() {
        return baSupplierMapper.selectEnableSupplier();
    }

    @Override
    public List<BaSupplier> selectSupplierBysId(Long sId) {
        List<BaSupplier> baSuppliers = baSupplierMapper.selectEnableSupplier();
        BaSupplier baSupplier = baSupplierMapper.selectBaSupplierBySId(sId);
        for (BaSupplier supplier : baSuppliers) {
            if (baSupplier!=null && supplier.getsId().equals(baSupplier.getsId())) {
                supplier.setFlag(true);
                break;
            }
        }
        return baSuppliers;
    }


    /**
     * 查询供应商列表
     * 
     * @param baSupplier 供应商
     * @return 供应商
     */
    @Override
    public List<BaSupplier> selectBaSupplierList(BaSupplier baSupplier)
    {
        return baSupplierMapper.selectBaSupplierList(baSupplier);
    }

    /**
     * 新增供应商
     * 
     * @param baSupplier 供应商
     * @return 结果
     */
    @Override
    public int insertBaSupplier(BaSupplier baSupplier)
    {
        baSupplier.setCreateTime(DateUtils.getNowDate());
        return baSupplierMapper.insertBaSupplier(baSupplier);
    }

    /**
     * 修改供应商
     * 
     * @param baSupplier 供应商
     * @return 结果
     */
    @Override
    public int updateBaSupplier(BaSupplier baSupplier)
    {
        baSupplier.setUpdateTime(DateUtils.getNowDate());
        return baSupplierMapper.updateBaSupplier(baSupplier);
    }

    /**
     * 批量删除供应商
     * 
     * @param sIds 需要删除的供应商主键
     * @return 结果
     */
    @Override
    public int deleteBaSupplierBySIds(String sIds)
    {
        return baSupplierMapper.deleteBaSupplierBySIds(Convert.toStrArray(sIds));
    }

    /**
     * 删除供应商信息
     * 
     * @param sId 供应商主键
     * @return 结果
     */
    @Override
    public int deleteBaSupplierBySId(Long sId)
    {
        return baSupplierMapper.deleteBaSupplierBySId(sId);
    }
}
